package com.lonely.web.controller.production;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lonely.common.core.domain.StatusInfo;
import com.lonely.common.core.domain.api.R;
import com.lonely.product.domain.dto.postfinishing.PostFinishingCompletedDTO;
import com.lonely.product.domain.dto.postfinishing.QueryOrderPostFinishingPageDTO;
import com.lonely.product.domain.dto.postfinishing.StartPostFinishingDTO;
import com.lonely.product.domain.vo.postfinishing.QueryOrderPostFinishingPageVO;
import com.lonely.product.service.IOrderPostFinishingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 黄志标
 * @date: 2025/7/24 14:02
 * @description: 后整请求处理器
 */
@RestController
@RequestMapping("/productionManager/postFinishing")
@Api(tags = "生产管理/后整管理")
public class OrderPostFinishingController {

    @Autowired
    private IOrderPostFinishingService orderPostFinishingService;

    /**
     * 分页查询
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "后整分页查询")
    public R<Page<QueryOrderPostFinishingPageVO>> page(@RequestBody @Validated QueryOrderPostFinishingPageDTO queryDto) {
        return R.data(this.orderPostFinishingService.page(queryDto));
    }

    /**
     * 获取状态信息
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/getStatusInfo")
    public R<List<StatusInfo>> getStatusInfo(@RequestBody @Validated QueryOrderPostFinishingPageDTO queryDto) {
        return R.data(this.orderPostFinishingService.getStatusInfo(queryDto));
    }

    /**
     * 获取默认的开始后整数
     *
     * @param postFinishingId
     * @return
     */
    @GetMapping("/getDefaultStartPostFinishingQuantity/{postFinishingId}")
    public R<String> getDefaultStartPostFinishingQuantity(@PathVariable("postFinishingId") Long postFinishingId) {
        return R.data(this.orderPostFinishingService.getDefaultStartPostFinishingQuantity(postFinishingId));
    }

    /**
     * 开始后整
     *
     * @param requestDto
     * @return
     */
    @PostMapping("/startPostFinishing")
    @SaCheckPermission("production:postFinishing:startPostFinishing")
    public R<Boolean> startPostFinishing(@RequestBody @Validated StartPostFinishingDTO requestDto) {
        this.orderPostFinishingService.startPostFinishing(requestDto);
        return R.status(true);
    }

    /**
     * 获取默认的后整完工数
     *
     * @param postFinishingId
     * @return
     */
    @GetMapping("/getDefaultCompletedPostFinishingQuantity/{postFinishingId}")
    public R<String> getDefaultCompletedPostFinishingQuantity(@PathVariable("postFinishingId") Long postFinishingId) {
        return R.data(this.orderPostFinishingService.getDefaultCompletedPostFinishingQuantity(postFinishingId));
    }


    /**
     * 后整完工
     *
     * @param requestDto
     * @return
     */
    @PostMapping("/postFinishingCompleted")
    @SaCheckPermission("production:postFinishing:postFinishingCompleted")
    public R<Boolean> postFinishingCompleted(@RequestBody @Validated PostFinishingCompletedDTO requestDto) {
        this.orderPostFinishingService.postFinishingCompleted(requestDto);
        return R.status(true);
    }

}
